<?= $this->element('reports_submenu', array('page'=>'index')) ?>
<?= $this->Form->create('Filter', array('url'=>'/reports', 'class'=>'filter')) ?>
	<?= $this->Form->submit(__('Filter'), array('div'=>false)) ?>
	
	<?= $this->Form->label('start.month', __('from').":", array('class'=>'inline auto')) ?>
	<?= $this->Form->select('start.month', $months, array('value'=>@$filter['start']['month'], 'empty'=>false, 'class'=>'medium')) ?>
	<?= $this->Form->select('start.year', $years, array('value'=>@$filter['start']['year'], 'empty'=>false, 'class'=>'small')) ?>

	<?= $this->Form->label('end.month', __('to').":", array('class'=>'inline', 'style'=>'width:50px')) ?>
	<?= $this->Form->select('end.month', $months, array('value'=>@$filter['end']['month'], 'empty'=>false, 'class'=>'medium')) ?>
	<?= $this->Form->select('end.year', $years, array('value'=>@$filter['end']['year'], 'empty'=>false, 'class'=>'small')) ?>
	
<?= $this->Form->end() ?><br clear="all">


<? if(empty($report)): ?>
	<?= __('Empty') ?>.
<?  else: ?>
	<table>
	<thead>
		<tr>
			<th rowspan="3"><?= __('voice') ?></th>
			<th rowspan="3"><?= __('firstname') ?>/<?= __('surname') ?></th>
			<? foreach($report as $year=>$yearData): ?>
				<th align="center" colspan="<?= count($yearData)*3 ?>"><?= $year ?></th>
			<? endforeach; ?>
			<th rowspan="2" colspan="4" align="center"><?= __('Total') ?></th>
		</tr>
		<tr>
			<? foreach($report as $year=>$yearData): ?>
				<? foreach($yearData as $month=>$monthData): ?>
					<th align="center" colspan="3"><?= $months[(int)$month] ?></th>
				<? endforeach; ?>
			<? endforeach; ?>
		</tr>
		<tr>
			<? foreach($report as $year=>$yearData): ?>
				<? foreach($yearData as $month=>$monthData): ?>
					<th align="center" title="<?= __('Rehearsal') ?>"><?= mb_substr(__('Rehearsal'), 0, 1, "utf-8") ?></th>
					<th align="center" title="<?= __('Liturgy') ?>"><?= mb_substr(__('Liturgy'), 0, 1, "utf-8") ?></th>
					<th align="center" title="<?= __('Rite') ?>"><?= mb_substr(__('Rite'), 0, 1, "utf-8") ?></th>
				<? endforeach; ?>
			<? endforeach; ?>
			<th align="center" title="<?= __('Rehearsal') ?>"><?= mb_substr(__('Rehearsal'), 0, 1, "utf-8") ?></th>
			<th align="center" title="<?= __('Liturgy') ?>"><?= mb_substr(__('Liturgy'), 0, 1, "utf-8") ?></th>
			<th align="center" title="<?= __('Rite') ?>"><?= mb_substr(__('Rite'), 0, 1, "utf-8") ?></th>
			<th align="center">=</th>
		</tr>
		<tr>
			<th colspan="2"></th>
			<? foreach($report as $year=>$yearData): ?>
				<? foreach($yearData as $month=>$monthData): ?>
					<th><?= $total[$year][$month]['Rehearsal'] ?></th>
					<th><?= $total[$year][$month]['Liturgy'] ?></th>
					<th><?= $total[$year][$month]['Rite'] ?></th>
				<? endforeach; ?>
			<? endforeach; ?>
			<th align="center"><?= array_sum_r(Set::extract('{n}.{n}.Rehearsal', $total)) ?></th>
			<th align="center"><?= array_sum_r(Set::extract('{n}.{n}.Liturgy', $total)) ?></th>
			<th align="center"><?= array_sum_r(Set::extract('{n}.{n}.Rite', $total)) ?></th>
			<th align="center"><?= array_sum_r(Set::extract('{n}.{n}.{s}', $total)) ?></th>
		</tr>
	</thead>
	<tbody>
		<? foreach($members as $member_id=>$memberData): ?>
		<tr>
			<td align="center"><?= __($memberData['voice']) ?></td>
			<td><?= $memberData['firstname'] ?> <?= $memberData['surname'] ?></td>
			<? foreach($report as $year=>$yearData): ?>
				<? foreach($yearData as $month=>$monthData): ?>
					<? foreach($monthData as $type=>$userData): ?>
					<td align="center"><?= $userData[$member_id] ?></td>
					<? endforeach; ?>
				<? endforeach; ?>
			<? endforeach; ?>
			<td align="center"><?= $total_member[$member_id]['Rehearsal'] ?></td>
			<td align="center"><?= $total_member[$member_id]['Liturgy'] ?></td>
			<td align="center"><?= $total_member[$member_id]['Rite'] ?></td>
			<td align="center"><?= array_sum($total_member[$member_id]) ?></td>
		</tr>
		<? endforeach; ?>
	</tbody>
	</table>
<? endif; ?>